﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Blade.IO;
using Blade.Metadata.CliLoader.Metadata.Tables;
using Blade.Metadata.CliLoader.Metadata;

namespace Blade.Metadata.CliLoader {
	class CliMetadataFile {
		ICliFileReader fileReader;
		IMetadataLoaderContext context;
		internal readonly CliTableCollection Tables = new CliTableCollection();

		public CliMetadataFile(ICliFileReader fileReader, IMetadataLoaderContext context) {
			this.fileReader = fileReader;
			this.context = context;
			Tables.Add(CreateTable<ModuleRow>(MetadataTable.Module));
			Tables.Add(CreateTable<TypeRefRow>(MetadataTable.TypeRef));
		}

		private CliTable<TRow> CreateTable<TRow>(MetadataTable tableId)
			where TRow : CliRow, new() {
			return new CliTable<TRow>(
				tableId,
				fileReader.GetRowCount(tableId),
				fileReader.OpenTable(tableId),
				context
			);
		}
	}
}
